package com.hiray.demos.ui_architect.litho

import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import com.facebook.litho.Column
import com.facebook.litho.ComponentContext
import com.facebook.litho.LithoView
import com.facebook.litho.widget.Text
import com.hiray.demos.R
import com.hiray.demos.ui_architect.litho.image.ColorComponent
import com.hiray.demos.ui_architect.litho.image.SingleImageComponent
import com.hiray.demos.ui_architect.litho.image.TrivialImageView
import com.hiray.demos.ui_architect.litho.list.ListItem

class LithoActivity : AppCompatActivity() {

    val imageUrl = "https://images.unsplash.com/photo-1553531768-f617f5ba7dd7?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=500&q=60"
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        val context = ComponentContext(this)
        val textComponent = Text.create(context)
                .textSizeSp(15f)
                .text("Hi Litho!")
                .build()

        val item = ListItem.create(context)
                .title("Hello World!")
                .subTitle("Ei")
                .build()

        val imageComponent = SingleImageComponent.create(context)
                .image(imageUrl)
                .widthDp(100f)
                .heightDp(100f)
                .build()

        val localImageComponent = TrivialImageView.create(context)
                .imageRes(R.drawable.ic_star_rating)
                .widthDip(50f)
                .heightDip(50f)
                .build()


        val colorComponent = ColorComponent.create(context)
                .colorValue("#FFFF0000")
                .widthDip(50f)
                .heightDip(50f)
                .build()

        val contentView = Column.create(context)
                .child(imageComponent)
                .child(localImageComponent)
                .child(colorComponent)
                .child(textComponent)
                .child(item).build()
        setContentView(LithoView.create(context, contentView))

    }
}
